﻿using System.Data.SQLite;

namespace RobosimAPI.Class
{
	public class Group
	{
        /*
		CREATE TABLE [group] (
        id                INTEGER,
        event_id          INTEGER,
        title             TEXT,
        can_build         INTEGER DEFAULT (1),
        can_remote        INTEGER DEFAULT (0),
        cover             TEXT,
        face_timing       INTEGER DEFAULT (1),
        need_face_auth    INTEGER DEFAULT (0),
        need_face_compare INTEGER DEFAULT (0) 
        );
		*/
        public int id;
        public int event_id;
        public string? title;
        public int can_build;
        public int can_remote;
        public string? cover;
        public int face_timing;
        public int need_face_auth;
        public int need_face_compare;
        public Group(int group_id)
        {
			using (var conn = new SQLiteConnection(Account.DB_CONNECTION_STRING))
            {
                conn.Open();
                using (var cmd = new SQLiteCommand(conn))
                {
                    cmd.CommandText = "SELECT * FROM [group] WHERE id = @id LIMIT 1";
                    cmd.Parameters.AddWithValue("@id", group_id);
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            id = reader.GetInt32(0);
                            event_id = reader.GetInt32(1);
                            title = reader.GetString(2);
                            can_build = reader.GetInt32(3);
                            can_remote = reader.GetInt32(4);
                            cover = reader.GetString(5);
                            face_timing = reader.GetInt32(6);
                            need_face_auth = reader.GetInt32(7);
                            need_face_compare = reader.GetInt32(8);
                        }
                    }
                }
                conn.Close();
                conn.Dispose();
            }
		}
        public Group() { }
	}
}
